angular.module('starter')
  .config(function($stateProvider) {
    $stateProvider.state('login', {
      url: '/login',
      templateUrl: 'templates/login/login.html',
      controller: 'loginCtrl',
      controllerAs: 'loginCtrl'
    })
  })
  .controller('loginCtrl', function($scope,$rootScope,$http) {
    var _this = $scope;
    this.requestData = {
      loginName: '',
      password: ''
    };

    this.cancle = function() {
      this.requestData.loginName = '';
      this.requestData.password = '';
    };

    this.login = function() {

      $http.post("qss/app/login", this.requestData).success(function(res) {
        if (res.success) {
          localStorage.setItem("userData",JSON.stringify(res.rows));
          $rootScope.userData = res.rows;
          _this.showAlert("登陆成功");
          _this.goNewPage('index');
        }else {
           _this.showAlert(res.message);
        }
      });
    }

  });